package cn.marinda.resturants.controller;

import cn.marinda.resturants.entity.Member;
import cn.marinda.resturants.entity.Staff;
import cn.marinda.resturants.enums.EntityJson;
import cn.marinda.resturants.global.Pages;
import cn.marinda.resturants.service.MemberService;
import cn.marinda.resturants.utils.ApiResult;
import cn.marinda.resturants.utils.IOUtils;
import cn.marinda.resturants.utils.PagesResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;

/** 会员控制器
 *
 * @version 1.0
 * @data 2021/12/2
 * @author Marinda
 *
 */
@RestController
@RequestMapping("/member")
public class MemberController {

    @Resource
    private MemberService memberService;

    /** 列表分页
     *
     * @date 2021/12/1
     * @return 结果
     */
    @RequestMapping("/pages")
    private PagesResult selectPages(@RequestParam("page") int page, @RequestParam("limit") int limit)
    {
        IPage<Member> memberIPage = memberService.selectMemberPage(new Pages<>(page,limit));
        return new PagesResult(0,memberIPage.getRecords(),(int)memberIPage.getTotal(),memberIPage.getSize());
    }

    /**
     * 会员列表
     *
     * @return 会员列表
     */
    @RequestMapping("/queryList")
    public ApiResult queryList() {
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,memberService.queryList());
    }

    /**
     * 添加会员
     *
     * @param member 会员
     * @version 1.0
     * @data 2021/12/2
     */
    @RequestMapping("/add")
    public ApiResult addMember(Member member) {
        return memberService.addMember(member) ? new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,null) : new ApiResult(ApiResult.ON_FAIL,ApiResult.FAIL_MESSAGE,null);
    }

    /**
     * 添加会员
     *
     * @param uid 会员
     * @version 1.0
     * @data 2021/12/2
     */
    @RequestMapping("/index")
    public ApiResult selectMemberUid(String uid) {
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE, Arrays.asList(memberService.selectMemberUid(uid)));
    }


    /**
     * 删除会员
     *
     * @param uid 会员
     * @return 结果
     */
    @RequestMapping("/delete")
    public ApiResult deleteMember(Integer uid) {
        return memberService.deleteMember(uid) ? new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,null) : new ApiResult(ApiResult.ON_FAIL,ApiResult.FAIL_MESSAGE,null);

    }

    /**
     * 修改会员
     *
     * @param member 会员
     * @return 结果
     */
    @RequestMapping("/update")
    public ApiResult updateMember(Member member) {
        return memberService.updateMember(member) ? new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,null) : new ApiResult(ApiResult.ON_FAIL,ApiResult.FAIL_MESSAGE,null);

    }

    /**
     * 查询指定会员的折扣
     *
     * @param uid uid
     * @return 折扣
     */
    @RequestMapping("/discount")
    public ApiResult selectDiscount(Integer uid) {
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,memberService.selectDiscount(uid));

    }

    /**
     * 查询会员数量
     *
     * @param uid uid
     * @return 数量
     */
    @RequestMapping("/count")
    public ApiResult selectCount(Integer uid) {
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,memberService.selectCount(uid));
    }

    /**
     * 查询会员礼券数
     *
     * @param uid 会员uid
     * @return 礼券数
     */
    @RequestMapping("/vochers")
    public ApiResult selectVochers(Integer uid) {
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,memberService.selectVochers(uid));

    }

    /**
     * 查询会员名称
     *
     * @param uid uid
     * @return 会员名称
     */
    @RequestMapping("/name")
    public ApiResult selectName(Integer uid) {
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,memberService.selectName(uid));

    }

    /**
     * 查询会员创建日期
     *
     * @param uid uid
     * @return 会员创建日期
     */
    @RequestMapping("/createDate")
    public ApiResult selectCreateDate(Integer uid) {
        return new ApiResult(ApiResult.ON_SUCCESS,ApiResult.SUCCESS_MESSAGE,memberService.selectCreateDate(uid));

    }
}
